﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.Domain.Entities;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using ITProject.Domain;

namespace ITProject.WebUI.Models.ProjectAdmin
{
    public class ProjectAdminCreateTeamViewModel
    {
        [Required(ErrorMessage = "Musisz podać nazwę zespołu")]
        [Display(Name = "Nazwa zespołu")]
        [MaxLength(30, ErrorMessage = "Nazwa zespołu może mieć maksymalnie 30 znaków")]
        [MinLength(4, ErrorMessage = "Nazwa zespołu musi zawierać co najmniej 4 znaki")]
        public string Name { get; set; }
        [Required(ErrorMessage = "Musisz podać opis zespołu")]
        [Display(Name = "Opis zespołu")]
        public string Description { get; set; }

        public int ProjectId { get; set; }
        public List<SelectListItem> ProjectUsers { get; set; }

        [Required(ErrorMessage = "Musisz wybrać lidera zespołu")]
        [Display(Name = "Lider zespołu")]
        public string Leader { get; set; }

        public static Team Convert(ProjectAdminCreateTeamViewModel vm, int leaderId)
        {
            Team team = new Team();
            team.Name = vm.Name;
            team.Description = vm.Description;
            team.DateOfCreate = DateTime.Now;
            team.LeaderId = leaderId;
            team.ProjectId = vm.ProjectId;
            return team;
        }

        public static void CompleteProjectUsers(ProjectAdminCreateTeamViewModel vm, string projectName, User[] projectUsers)
        {
            vm.ProjectUsers = new List<SelectListItem>(projectUsers.Length);
            foreach (User user in projectUsers)
                vm.ProjectUsers.Add(new SelectListItem { Text = user.Login });
        }
    }
}
